<?php
/**
 * YouNet
 *
 * @category   Application_Extensions
 * @package    Auction
 * @copyright  Copyright 2011 YouNet Developments
 * @license    http://www.modules2buy.com/
 * @version    $Id: search auctions
 * @author     Minh Nguyen
 */
class Ynauction_Widget_SearchYnauctionsController extends Engine_Content_Widget_Abstract
{
	public function indexAction()
  {  
    $this->view->form = $form = new Ynauction_Form_Search();
  // Populate form
    $this->view->categories = $categories = Engine_Api::_()->ynauction()->getCategories(0);
    foreach( $categories as $category )
    {
      $form->category->addMultiOption($category->category_id, $category->title);
    }
    $post = Engine_Api::_()->getItem('ynauction_param', 1)->toArray();
    if($post['category'] > 0)
	{
		if($post['subcategory'] > 0)
		{
			$category  = Engine_Api::_()->getItem('ynauction_category', $post['subcategory']);
			if($category->parent != $post['category'])
				$post['subcategory'] = 0;
		}
		$this->view->subcategories = $subcategories = Engine_Api::_()->ynauction()->getCategories($post['category']);
	    foreach( $subcategories as $subcategory )
	    {
	      $form->subcategory->addMultiOption($subcategory->category_id, $subcategory->title);
	    }
	}
    else
      $post['subcategory'] = 0;    
    // Process form
    $form->isValid($post);
  }
}